﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace ZOIL.Library.Behaviors
{
    public class Connection : INotifyPropertyChanged
    {
        #region private fields

        public FrameworkElement Source { get; set; }
        public FrameworkElement Target { get; set; }

        public Geometry ConnectionGeometry { get; set; }

        public Point StartPoint { get; set; }

        /// <summary>
        /// The <see cref="EndPoint" /> property's name.
        /// </summary>
        public const string EndPointPropertyName = "EndPoint";

        private Point _endPoint;

        /// <summary>
        /// Sets and gets the EndPoint property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public Point EndPoint
        {
            get
            {
                return _endPoint;
            }

            set
            {
                if (_endPoint == value)
                {
                    return;
                }

                _endPoint = value;
                RaisePropertyChanged(EndPointPropertyName);
            }
        }

        #endregion

        public Connection(Point startPoint)
        {
            StartPoint = startPoint;
        }

        #region INotifyPropertyChanged
        
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        } 

        #endregion
    }
}
